package com.test.testcrash;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;

/**
 * @author ruiding
 * @date 2016/4/22
 */
public class MyService2 extends Service {
    private final String TAG = "crashcollect_MyService2";

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "onCreate");
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(TAG, "onStartCommand");
        if (intent != null) {
            String cmd = intent.getStringExtra("crash");
            if (!TextUtils.isEmpty(cmd)) {
                makeProcess1Crash();
            }
        }
        return super.onStartCommand(intent, flags, startId);
    }

    private void makeProcess1Crash() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                SystemClock.sleep(1000);
                int data[] = new int[1];
                data[2] = 3;
            }
        }).start();
    }
}
